<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>医院登录界面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #F2F7FF;
            margin: 0;
            padding: 0;
        }

        .login-container {
            width: 100%;
            max-width: 400px;
            margin: 100px auto;
            padding: 20px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }

        h1 {
            text-align: center;
            color: #0066B3;
            margin-bottom: 20px;
        }

        .input-group {
            margin-bottom: 15px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #333;
        }

        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #0066B3;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #004D8C;
        }

        .hidden {
            display: none;
        }

    </style>
</head>
<body>
<div class="login-container">
    <h1>医院登录</h1>
    <form id="login-form">
        <div class="input-group">
            <label for="username">用户名：</label>
            <input type="text" id="username" name="username" required>
        </div>
        <div class="input-group">
            <label for="password">密码：</label>
            <input type="password" id="password" name="password" required>
        </div>
        <button type="submit">登录</button>
        <div id="login-error" style="color:red " class="hidden">登录失败，请检查您的用户名和密码。</div>
    </form>
</div>
<script>
    document.getElementById('login-form').addEventListener('submit', function(e) {
        e.preventDefault();
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        fetch('/web/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`
        })
            .then(response => response.text())
            .then(data => {
                if (data === 'success') {
                    // 登录成功，跳转到相应页面
                    window.location.href = 'index.html';
                } else {
                    // 显示登录失败信息
                    document.getElementById('login-error').classList.remove('hidden');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById('login-error').innerHTML = '登录失败，网络错误，请稍后再试。';
                document.getElementById('login-error').classList.remove('hidden');
            });
    });
</script>
</body>
</html>
